package scene

import (
	"container/list"
	"time"
)

var InsManager InsSceneManager
var MapScene map[int64]GameScene
var TimerList *list.List

type InsSceneManager struct {
}

func init() {
	InsManager = InsSceneManager{}
	MapScene = make(map[int64]GameScene)
	TimerList = list.New()
}

func (ins InsSceneManager) Start() {
	//移动timer
	moveEvent := TimerEvent{InterVal: 1000}
	MonsterMap := make(map[int32]map[int64]*Monster)
	gameScene := new(GameScene)
	monster := NewMonster(new(Person), gameScene)
	m := make(map[int64]*Monster)
	m[1] = monster
	MonsterMap[1] = m
	gameScene.MonsterMap = MonsterMap
	go ins.createSceneMoveTimer(moveEvent, gameScene)
	//AI Timer
	go ins.createScneAiTimer(moveEvent, gameScene)
}

func (ins InsSceneManager) BrushSceneObj() {

}

func (ins InsSceneManager) CreateSceneObj() {

}

func (ins InsSceneManager) createSceneMoveTimer(event TimerEvent, scene *GameScene) {
	t := time.NewTicker(time.Duration(event.InterVal) * time.Millisecond)
	for {
		select {
		case <-t.C:
			MonsterStep(scene)
		}
	}
	TimerList.PushBack(t)
}

func (ins InsSceneManager) createScneAiTimer(event TimerEvent, scene *GameScene) {
	t := time.NewTicker(time.Duration(event.InterVal) * time.Millisecond)
	for {
		select {
		case <-t.C:
			MonsteAiAction(scene)
		}
	}
	TimerList.PushBack(t)
}
